<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./lib/axios.min.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
	let cancelHandler = null;
    axios.defaults.timeout = 1000;
	btns[0].onclick = async function () {
		try {
			if(cancelHandler) cancelHandler();
			const {data} = await axios.get("http://zhangpeiyue.com/scoreList",{
				cancelToken:new axios.CancelToken(function(cancel){
					cancelHandler = cancel;
                })
            });
			console.log(data);
		} catch (err) {
			console.log(axios.isCancel(err));
			console.log(err);
		}

	}
	btns[1].onclick = function(){
		if(cancelHandler) cancelHandler();
    }
</script>
</html>